package org.example.multiThreading.threadPool;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class TestSingleThreadExecutor {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        /*
        SingleThreadExecutor
        单线程线程池。特点是线程池中只有一个线程（核心线程），线程执行完任务立即回收，使用有界阻塞队列（容量未指定，使用默认值Integer.MAX_VALUE）
        */
        ExecutorService service = Executors.newSingleThreadExecutor();

        //创建TestCallable，并加入线程池
        for (int i = 0; i < 10; i++) {
            TestCallable callable = new TestCallable();
            System.out.println(service.submit(callable).get());
        }

        //关闭线程池
        service.shutdown();
    }
}
